package gtkwire.widget;

import gtkwire.gobject.*;
import gtkwire.*;

public class GtkTreeView extends GtkContainer
{
	/* Selection modes */
	public static final int SELECTION_NONE = 0;
	public static final int SELECTION_SINGLE = 1;
 	public static final int SELECTION_BROWSE = 2;
 	public static final int SELECTION_MULTIPLE = 3;

	private GtkTreeModel model = null;

	public GtkTreeView()
	{
		super();
		this.widgetType = WT_GtkTreeView;
		gtkCreate();
	}

	public GtkTreeView( String name, GladeKey key )
	{
		super( name, key );
		this.widgetType = WT_GtkTreeView;
	}

	public void setModel( GtkTreeModel model )
	{
		this.model = model;
		app().sendCommand( name, GTKWireCommand.TW_SET_MODEL, model.getId() );
	}

	public void appendColumn( GtkTreeViewColumn column )
	{
		app().sendCommand( name, GTKWireCommand.TW_APPEND, column.getId() );
	}

	public void setSelectionMode( int mode )
	{
		app().sendCommand( name, GTKWireCommand.TW_SET_SELECTION, mode );
	}

	public void setSelected( GtkTreeRow row, boolean value )
	{
		String[] msg = { row.getAddr(), Boolean.toString( value ) };
		app().sendCommand( name, GTKWireCommand.TW_SET_SEL_ROW, msg );
	}

	public void setAllSelected( boolean value )
	{
		app().sendCommand( name, GTKWireCommand.TW_SET_SEL_ALL, value );
	}

	public GtkTreeRowIter[] getSelected()
	{
		if( model == null ) return null;
		GTKWireMessage answer = app().sendCommandRequest( name, widgetType, GTKWireCommandRequest.TW_GET_SELECTED, null );
		String[] strs = (String[]) answer.getMessageObject();
		if( strs == null ) return null;
		GtkTreeRowIter[] rows = new GtkTreeRowIter[strs.length];
		for( int i = 0; i < strs.length; i++)
			rows[i] = new GtkTreeRowIter( strs[i], model );
		return rows;
	}

	// toimiiko?
	public void setCursor( GtkTreeRow row, GtkTreeViewColumn col, boolean editable )
	{
		String[] msg = { row.getAddr(), Integer.toString( col.getId() ), Boolean.toString( editable ) };
		app().sendCommand( name, GTKWireCommand.TW_SET_CURSOR, msg );
	}
	

}//end class
